/*-+-*****************************************************************************
 Copyright (C) 2009-2012 Oceanside Software Corporation (R)
 Dallas, Texas

 Author       : Jason T. Brower
 Purpose      : This file is part of a point-of-sale software package
                originally written for Table-Service Restaurants.
              
 Date         : July 8th of 2012
              
 History      : The application that this software file belongs to was 
                written over a 3-Year period.  The first version was written
                in C# .Net 3.5 using Windows Forms.  Being new to .Net at
                the time, I soon learned of Windows Presentation Foundation,
                liked the graphics capabilities and databinding so I
                migrated to WPF.  When the .Net 4.0 framework was released
                the application was migrated from 3.5 to 4.0. Now today,
                .Net 4.5 RC is out and I was already in process of migrating
                before I made this public.
                
Excuse Me     : Please excuse the coding style, it is not representative of
                my typical work.  During the three years I was under a very
                tight budget, constantly running out of funding and was 
                working 18 hour days hyped up on 5-Hour Energy.  The 
                design is not textbook.  It is monolythic because of
                previous issues I will not get into.  There are few comments
                in the code and the ones that are there may be incorrect.
                
What it is not: This is not the exact version that I took through PA-DSS 2.0
                nor is it the exact version running at my customer sites.
                I removed some details for security purposes including some
                encryption algorithms.  The reporting was removed because
                I was including a third party library that cannot be 
                published with this Open Source.
                
What it is    : This application has been running at high volume restaraunts
                for over a year.  It never freezes, crashes or does anything
                unexpected.  So long as it is built, installed and configured
                correctly, it is a strong system that we can all enhance.

Contact       : Please note that I can no longer work for free.  However, you
                can reach me at information@oceansidesw.com.                                                      

*********************************************************************************/
using System;
using System.Windows.Forms;

namespace Oceanside
{
    public class ScanCodes
    {
        /// <summary>
        /// Keep track of the shift and caps lock so we know what type
        /// of data to return.
        /// </summary>
        private bool isShifted = false;
        private bool isCaps = false;

        public bool IsCaps
        {
            get { return isCaps; }
            set { isCaps = value; }
        }

        /// <summary>
        /// Since this is a static class, we need the ability to reset the caps casing.
        /// </summary>
        public void ResetCase()
        {
            isShifted = false;
            isCaps = false;
        }

        /// <summary>
        /// Convert a keyboard scan code to a char.  Note that not all of them are mapped.
        /// </summary>
        /// <param name="keyCode"></param>
        /// <returns></returns>
        public String ScancodeToAsciiStrChar(Keys keyCode)
        {
            ///If shifted or in all caps return the upper case or alt code.
            if (isCaps || isShifted)
            {
                isShifted = false;
                switch (keyCode)
                {
                    //
                    // Summary:
                    //     The CAPS LOCK key.
                    case Keys.CapsLock:
                        isCaps = !isCaps;
                        return null;
                    //
                    // Summary:
                    //     The 0 key.
                    case Keys.D0:
                        return ")";
                    //
                    // Summary:
                    //     The 1 key.
                    case Keys.D1:
                        return "!";
                    //
                    // Summary:
                    //     The 2 key.
                    case Keys.D2:
                        return "@";
                    //
                    // Summary:
                    //     The 3 key.
                    case Keys.D3:
                        return "#";
                    //
                    // Summary:
                    //     The 4 key.
                    case Keys.D4:
                        return "$";
                    //
                    // Summary:
                    //     The 5 key.
                    case Keys.D5:
                        return "%";
                    //
                    // Summary:
                    //     The 6 key.
                    case Keys.D6:
                        return "^";
                    //
                    // Summary:
                    //     The 7 key.
                    case Keys.D7:
                        return "&";
                    //
                    // Summary:
                    //     The 8 key.
                    case Keys.D8:
                        return "*";
                    //
                    // Summary:
                    //     The 9 key.
                    case Keys.D9:
                        return "(";
                    //
                    // Summary:
                    //     The A key.
                    case Keys.A:
                        return "A";
                    //
                    // Summary:
                    //     The B key.
                    case Keys.B:
                        return "B";
                    //
                    // Summary:
                    //     The C key.
                    case Keys.C:
                        return "C";
                    //
                    // Summary:
                    //     The D key.
                    case Keys.D:
                        return "D";
                    //
                    // Summary:
                    //     The E key.
                    case Keys.E:
                        return "E";
                    //
                    // Summary:
                    //     The F key.
                    case Keys.F:
                        return "F";
                    //
                    // Summary:
                    //     The G key.
                    case Keys.G:
                        return "G";
                    //
                    // Summary:
                    //     The H key.
                    case Keys.H:
                        return "H";
                    //
                    // Summary:
                    //     The I key.
                    case Keys.I:
                        return "I";
                    //
                    // Summary:
                    //     The J key.
                    case Keys.J:
                        return "J";
                    //
                    // Summary:
                    //     The K key.
                    case Keys.K:
                        return "K";
                    //
                    // Summary:
                    //     The L key.
                    case Keys.L:
                        return "L";
                    //
                    // Summary:
                    //     The M key.
                    case Keys.M:
                        return "M";
                    //
                    // Summary:
                    //     The N key.
                    case Keys.N:
                        return "N";
                    //
                    // Summary:
                    //     The O key.
                    case Keys.O:
                        return "O";
                    //
                    // Summary:
                    //     The P key.
                    case Keys.P:
                        return "P";
                    //
                    // Summary:
                    //     The Q key.
                    case Keys.Q:
                        return "Q";
                    //
                    // Summary:
                    //     The R key.
                    case Keys.R:
                        return "R";
                    //
                    // Summary:
                    //     The S key.
                    case Keys.S:
                        return "S";
                    //
                    // Summary:
                    //     The T key.
                    case Keys.T:
                        return "T";
                    //
                    // Summary:
                    //     The U key.
                    case Keys.U:
                        return "U";
                    //
                    // Summary:
                    //     The V key.
                    case Keys.V:
                        return "V";
                    //
                    // Summary:
                    //     The W key.
                    case Keys.W:
                        return "W";
                    //
                    // Summary:
                    //     The X key.
                    case Keys.X:
                        return "X";
                    //
                    // Summary:
                    //     The Y key.
                    case Keys.Y:
                        return "Y";
                    //
                    // Summary:
                    //     The Z key.
                    case Keys.Z:
                        return "Z";
                    //
                    // Summary:
                    //     The 0 key on the numeric keypad.
                    case Keys.NumPad0:
                        return "0";
                    //
                    // Summary:
                    //     The 1 key on the numeric keypad.
                    case Keys.NumPad1:
                        return "1";
                    //
                    // Summary:
                    //     The 2 key on the numeric keypad.
                    case Keys.NumPad2:
                        return "2";
                    //
                    // Summary:
                    //     The 3 key on the numeric keypad.
                    case Keys.NumPad3:
                        return "3";
                    //
                    // Summary:
                    //     The 4 key on the numeric keypad.
                    case Keys.NumPad4:
                        return "4";
                    //
                    // Summary:
                    //     The 5 key on the numeric keypad.
                    case Keys.NumPad5:
                        return "5";
                    //
                    // Summary:
                    //     The 6 key on the numeric keypad.
                    case Keys.NumPad6:
                        return "6";
                    //
                    // Summary:
                    //     The 7 key on the numeric keypad.
                    case Keys.NumPad7:
                        return "7";
                    //
                    // Summary:
                    //     The 8 key on the numeric keypad.
                    case Keys.NumPad8:
                        return "8";
                    //
                    // Summary:
                    //     The 9 key on the numeric keypad.
                    case Keys.NumPad9:
                        return "9";
                    //
                    // Summary:
                    //     The OEM Semicolon key on a US standard keyboard (Windows 2000 or later).
                    case Keys.OemSemicolon:
                        return "@";
                    //
                    // Summary:
                    //     The OEM plus key on any country/region keyboard (Windows 2000 or later).
                    case Keys.Oemplus:
                        return "+";
                    //
                    // Summary:
                    //     The OEM comma key on any country/region keyboard (Windows 2000 or later).
                    case Keys.Oemcomma:
                        return "<";
                    //
                    // Summary:
                    //     The OEM minus key on any country/region keyboard (Windows 2000 or later).
                    case Keys.OemMinus:
                        return "_";
                    //
                    // Summary:
                    //     The OEM period key on any country/region keyboard (Windows 2000 or later).
                    case Keys.OemPeriod:
                        return ">";
                    //
                    // Summary:
                    //     The OEM question mark key on a US standard keyboard (Windows 2000 or later).
                    case Keys.OemQuestion:
                        return "?";

                    //
                    // Summary:
                    //     The OEM tilde key on a US standard keyboard (Windows 2000 or later).
                    case Keys.Oemtilde:
                        return "~";
                    //
                    // Summary:
                    //     The OEM open bracket key on a US standard keyboard (Windows 2000 or later).
                    case Keys.OemOpenBrackets:
                        return "{";
                    //
                    // Summary:
                    //     The OEM pipe key on a US standard keyboard (Windows 2000 or later).
                    case Keys.OemPipe:
                        return "|";
                    //
                    // Summary:
                    //     The OEM close bracket key on a US standard keyboard (Windows 2000 or later).
                    case Keys.OemCloseBrackets:
                        return "}";
                    //
                    // Summary:
                    //     The OEM singled/double quote key on a US standard keyboard (Windows 2000
                    //     or later).
                    case Keys.OemQuotes:
                        return "\"";
                    //
                    // Summary:
                    //     The OEM angle bracket or backslash key on the RT 102 key keyboard (Windows
                    //     2000 or later).
                    case Keys.OemBackslash:
                        return "|";
                    //
                    // Summary:
                    //     The SHIFT modifier key.
                    case Keys.Shift:
                        isShifted = true;
                        return null;
                    //
                    // Summary:
                    //     The SHIFT modifier key.
                    case Keys.LShiftKey:
                        isShifted = true;
                        return null;
                    //
                    // Summary:
                    //     The SHIFT modifier key.
                    case Keys.RShiftKey:
                        isShifted = true;
                        return null;

                    //
                    // Summary:
                    //     The SHIFT modifier key.
                    case Keys.Space:
                        return " ";
                    default:
                        return null;
                }

            }
            ///This is not a caps lock or shifted key.
            else
            { 
                switch (keyCode)
                {
                    //
                    // Summary:
                    //     The CAPS LOCK key.
                    case Keys.CapsLock:
                        isCaps = !isCaps;
                        return null;
                    //
                    // Summary:
                    //     The 0 key.
                    case Keys.D0:
                        return "0";
                    //
                    // Summary:
                    //     The 1 key.
                    case Keys.D1:
                        return "1";
                    //
                    // Summary:
                    //     The 2 key.
                    case Keys.D2:
                        return "2";
                    //
                    // Summary:
                    //     The 3 key.
                    case Keys.D3:
                        return "3";
                    //
                    // Summary:
                    //     The 4 key.
                    case Keys.D4:
                        return "4";
                    //
                    // Summary:
                    //     The 5 key.
                    case Keys.D5:
                        return "5";
                    //
                    // Summary:
                    //     The 6 key.
                    case Keys.D6:
                        return "6";
                    //
                    // Summary:
                    //     The 7 key.
                    case Keys.D7:
                        return "7";
                    //
                    // Summary:
                    //     The 8 key.
                    case Keys.D8:
                        return "8";
                    //
                    // Summary:
                    //     The 9 key.
                    case Keys.D9:
                        return "9";
                    //
                    // Summary:
                    //     The A key.
                    case Keys.A:
                        return "a";
                    //
                    // Summary:
                    //     The B key.
                    case Keys.B:
                        return "b";
                    //
                    // Summary:
                    //     The C key.
                    case Keys.C:
                        return "c";
                    //
                    // Summary:
                    //     The D key.
                    case Keys.D:
                        return "d";
                    //
                    // Summary:
                    //     The E key.
                    case Keys.E:
                        return "e";
                    //
                    // Summary:
                    //     The F key.
                    case Keys.F:
                        return "f";
                    //
                    // Summary:
                    //     The G key.
                    case Keys.G:
                        return "g";
                    //
                    // Summary:
                    //     The H key.
                    case Keys.H:
                        return "h";
                    //
                    // Summary:
                    //     The I key.
                    case Keys.I:
                        return "i";
                    //
                    // Summary:
                    //     The J key.
                    case Keys.J:
                        return "j";
                    //
                    // Summary:
                    //     The K key.
                    case Keys.K:
                        return "k";
                    //
                    // Summary:
                    //     The L key.
                    case Keys.L:
                        return "l";
                    //
                    // Summary:
                    //     The M key.
                    case Keys.M:
                        return "m";
                    //
                    // Summary:
                    //     The N key.
                    case Keys.N:
                        return "n";
                    //
                    // Summary:
                    //     The O key.
                    case Keys.O:
                        return "o";
                    //
                    // Summary:
                    //     The P key.
                    case Keys.P:
                        return "p";
                    //
                    // Summary:
                    //     The Q key.
                    case Keys.Q:
                        return "q";
                    //
                    // Summary:
                    //     The R key.
                    case Keys.R:
                        return "r";
                    //
                    // Summary:
                    //     The S key.
                    case Keys.S:
                        return "s";
                    //
                    // Summary:
                    //     The T key.
                    case Keys.T:
                        return "t";
                    //
                    // Summary:
                    //     The U key.
                    case Keys.U:
                        return "u";
                    //
                    // Summary:
                    //     The V key.
                    case Keys.V:
                        return "v";
                    //
                    // Summary:
                    //     The W key.
                    case Keys.W:
                        return "w";
                    //
                    // Summary:
                    //     The X key.
                    case Keys.X:
                        return "x";
                    //
                    // Summary:
                    //     The Y key.
                    case Keys.Y:
                        return "y";
                    //
                    // Summary:
                    //     The Z key.
                    case Keys.Z:
                        return "z";
                    //
                    // Summary:
                    //     The 0 key on the numeric keypad.
                    case Keys.NumPad0:
                        return "0";
                    //
                    // Summary:
                    //     The 1 key on the numeric keypad.
                    case Keys.NumPad1:
                        return "1";
                    //
                    // Summary:
                    //     The 2 key on the numeric keypad.
                    case Keys.NumPad2:
                        return "2";
                    //
                    // Summary:
                    //     The 3 key on the numeric keypad.
                    case Keys.NumPad3:
                        return "3";
                    //
                    // Summary:
                    //     The 4 key on the numeric keypad.
                    case Keys.NumPad4:
                        return "4";
                    //
                    // Summary:
                    //     The 5 key on the numeric keypad.
                    case Keys.NumPad5:
                        return "5";
                    //
                    // Summary:
                    //     The 6 key on the numeric keypad.
                    case Keys.NumPad6:
                        return "6";
                    //
                    // Summary:
                    //     The 7 key on the numeric keypad.
                    case Keys.NumPad7:
                        return "7";
                    //
                    // Summary:
                    //     The 8 key on the numeric keypad.
                    case Keys.NumPad8:
                        return "8";
                    //
                    // Summary:
                    //     The 9 key on the numeric keypad.
                    case Keys.NumPad9:
                        return "9";
                    //
                    // Summary:
                    //     The OEM Semicolon key on a US standard keyboard (Windows 2000 or later).
                    case Keys.OemSemicolon:
                        return ";";
                    //
                    // Summary:
                    //     The OEM plus key on any country/region keyboard (Windows 2000 or later).
                    case Keys.Oemplus:
                        return "=";
                    //
                    // Summary:
                    //     The OEM comma key on any country/region keyboard (Windows 2000 or later).
                    case Keys.Oemcomma:
                        return ",";
                    //
                    // Summary:
                    //     The OEM minus key on any country/region keyboard (Windows 2000 or later).
                    case Keys.OemMinus:
                        return "-";
                    //
                    // Summary:
                    //     The OEM period key on any country/region keyboard (Windows 2000 or later).
                    case Keys.OemPeriod:
                        return ".";
                    //
                    // Summary:
                    //     The OEM question mark key on a US standard keyboard (Windows 2000 or later).
                    case Keys.OemQuestion:
                        return "/";

                    //
                    // Summary:
                    //     The OEM tilde key on a US standard keyboard (Windows 2000 or later).
                    case Keys.Oemtilde:
                        return "`";
                    //
                    // Summary:
                    //     The OEM open bracket key on a US standard keyboard (Windows 2000 or later).
                    case Keys.OemOpenBrackets:
                        return "[";
                    //
                    // Summary:
                    //     The OEM pipe key on a US standard keyboard (Windows 2000 or later).
                    case Keys.OemPipe:
                        return "\\";
                    //
                    // Summary:
                    //     The OEM close bracket key on a US standard keyboard (Windows 2000 or later).
                    case Keys.OemCloseBrackets:
                        return "]";
                    //
                    // Summary:
                    //     The OEM singled/double quote key on a US standard keyboard (Windows 2000
                    //     or later).
                    case Keys.OemQuotes:
                        return "'";
                    //
                    // Summary:
                    //     The OEM angle bracket or backslash key on the RT 102 key keyboard (Windows
                    //     2000 or later).
                    case Keys.OemBackslash:
                        return "\\";
                    //
                    // Summary:
                    //     The SHIFT modifier key.
                    case Keys.LShiftKey:
                        isShifted = true;
                        return null;
                    //
                    // Summary:
                    //     The SHIFT modifier key.
                    case Keys.Space:
                        return " ";
                    default:
                        return null;
                }
            }
        }
    }
}
